package easy;

import java.util.HashSet;
import java.util.Set;

public class M16_15_珠玑妙算 {
    public static void main(String[] args) {
        int[] res = new M16_15_珠玑妙算().masterMind("RGRB", "BBBY");
        for (int re : res) {
            System.out.print(re + ",");
        }
    }

    /**
     * 这个是错的，只通过了一半示例。
     * @param solution
     * @param guess
     * @return
     */
    public int[] masterMind(String solution, String guess) {
        int[] res = new int[2];

        if (guess == null || guess.equals("")) return res;

        Set<Character> set = new HashSet<>();
        for (int i=0; i<solution.length(); i++){
            set.add(guess.charAt(i));
        }

        for (int i=0; i<solution.length(); i++){
            char sc = solution.charAt(i);
            char gc = guess.charAt(i);

            if (sc == gc) {
                res[0] = res[0] + 1;
            } else {
                if (set.contains(sc)) {
                    res[1] = res[1] + 1;
                }
            }
        }
        return res;

    }
}
